﻿
using System.IO.IsolatedStorage;
using System.IO;
namespace CDFWPUG.Helpers
{
    public class IsolatedStorageHelper
    {



        public static bool FileExists(string path)
        {

            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();


            if(store.FileExists(path))
            {
                return true;
            }
            else
            {
                return false;
            }

        }


        public static string LoadFile(string path)
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream save = new IsolatedStorageFileStream(path, FileMode.Open, store);
            BinaryReader reader = new BinaryReader(save);
            string mystring = reader.ReadString();
            reader.Close();
            return mystring;
        }


        public static void SaveFile(string path, string data)
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); // grab the storage
            FileStream stream = store.OpenFile(path, FileMode.Create); // Open a file in Create mode
            BinaryWriter writer = new BinaryWriter(stream);
            writer.Write(data);
            writer.Close();
            stream.Close();
        }

        public static void  DeleteFile(string path)
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); // grab the storage
            store.DeleteFile(path);
        }

        public static void DeleteDirectory(string path)
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); // grab the storage
            store.DeleteDirectory(path);
        }










    }
}
